﻿namespace BM.Tools.WebControls.MForm.Controls.Helper
{
    using System.Web.UI;

    /// <summary>
    /// A custom client-side link button
    /// </summary>
    public class CustomButton : Button
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomButton"/> class. 
        /// </summary>
        /// <param name="itemId">
        /// The itemId.
        /// </param>
        /// <param name="text">
        /// The text inside the button.
        /// </param>
        /// <param name="onClientClick">
        /// The on client click.
        /// </param>
        public CustomButton(string itemId, string text, string onClientClick)
        {
            ItemId = itemId;
            Text = text;
            OnClientClick = onClientClick;
        }

        /// <summary>
        /// Gets ClientID.
        /// </summary>
        /// <value>
        /// The client id.
        /// </value>
        public override string ClientID
        {
            get
            {
                return "s_" + ItemId;
            }
        }

        /// <summary>
        /// Gets or sets ItemId.
        /// </summary>
        /// <value>
        /// The item id.
        /// </value>
        public string ItemId
        {
            get;
            set;
        }

        /// <summary>
        /// render the attributes of the anchor
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        protected override void RenderAnchorAttributes(HtmlTextWriter writer)
        {
            base.RenderAnchorAttributes(writer);
            writer.AddAttribute("id", "b_" + ItemId);
        }
    }
}